<?php
class admin_approve extends Admin_Controller
{
	public $menu_id = 17;
	public function __construct()
	{
		parent::__construct();
		$this->load->model('approve/approve_model','approve');		
	}
	
	public function index()
	{
		$menu_id = $this->menu_id;
		$data['menu_id'] = $menu_id;		
		$menu_name = GetMenuProperty($menu_id,'title');
		$data['urlpage']="admin_approve";
		if(is_login()){
			if(permission($menu_id, 'canview')=='')redirect('admin');
			$condition = "1=1";
			//$condition .= @$_GET['type']!='' ? " AND page='".$_GET['type']."'" : "";
			$data['dataList'] = $this->approve->get();
			$data['pagination'] = $this->approve->pagination();
			$this->template->build('index',$data);
		}
		else{
			
			redirect('admin');	
		}
	}
	public function form($id=FALSE){
		$menu_id=$this->menu_id;
		$curr_menu = $this->db->getone("SELECT title FROM admin_menu where id=".$menu_id);					
		$data['id'] = $id;
		$data['rs'] = @$this->approve->get_row($id);
		if($id>0){
		//$action='View';
		//$description = $action.' '.$curr_menu.' : '.$data['rs']['Title'];		
		//save_log($menu_id,$action,$description);			
		}
		$this->template->build('form',$data);
	}



	public function save(){
		//$this->db->debug = true;
		$menu_id=17;	
		$menu_name = GetMenuProperty($menu_id,'title');
		if($_POST['id']!='')
		{
			if(permission($menu_id, 'canedit')=='')redirect('admin_approve');
		//	$action='Update';
		//	$description = $action.' '.$menu_name.' : '.$_POST['Title'];		
		//	save_log($menu_id,$action,$description);
		}else{
			if(permission($menu_id, 'canadd')=='')redirect('admin_approve');	
			//$action='Add';
			//$description = $action.' '.$menu_name.' : '.$_POST['Title'];		
			//save_log($menu_id,$action,$description);
		}	
		if(isset($_POST['RequestDate']))$_POST['RequestDate'] = date_to_mysql($_POST['RequestDate']);	
		if(isset($_POST['ApproveStartDate']))$_POST['ApproveStartDate'] = date_to_mysql($_POST['ApproveStartDate']);	
		if(isset($_POST['ApproveEndDate']))$_POST['ApproveEndDate'] = date_to_mysql($_POST['ApproveEndDate']);	
		$id = $this->approve->save($_POST);		
		//set_notify('success', lang('save_data_complete'));
		redirect('admin_approve');
	} 
	function delete($id=FALSE){
		$menu_id=17;
		$menu_name = GetMenuProperty($menu_id,'title');
		if(permission($menu_id, 'candelete')=='')redirect('admin_approve');
		if($id){
			//$data = $this->approve->get_row($id);
			//$action='Delete';
			//$description = $action.' '.$menu_name.' : '.$data['Title'];		
			//save_log($menu_id,$action,$description);
			$this->approve->delete($id);
			//set_notify('success', lang('delete_data_complete'));
		}
		redirect('admin_approve');
	}
}
?>